unit uJfglWebModule;

interface

uses
  SysUtils, Classes, HTTPApp, 
  WSDLPub, SOAPPasInv, SOAPHTTPPasInv, SOAPHTTPDisp,
  WebBrokerSOAP, AppEvnts, InvokeRegistry, WSDLIntf, TypInfo, WebServExp,
  WSDLBind, XMLSchema;

type
  TjfglWebModule = class(TWebModule)
    HTTPSoapDispatcher1: THTTPSoapDispatcher;
    HTTPSoapPascalInvoker1: THTTPSoapPascalInvoker;
    WSDLHTMLPublish1: TWSDLHTMLPublish;
    ApplicationEvents1: TApplicationEvents;
    procedure WebModule1DefaultHandlerAction(Sender: TObject;
      Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    procedure WebModuleException(Sender: TObject; E: Exception;
      var Handled: Boolean);
    procedure ApplicationEvents1Exception(Sender: TObject; E: Exception);
  private
    { Private declarations }
    procedure SaveLog(const sMsg:string);
  public
    { Public declarations }
  end;

var
  jfglWebModule: TjfglWebModule;

implementation

{$R *.dfm}

procedure TjfglWebModule.ApplicationEvents1Exception(Sender: TObject;
  E: Exception);
begin
  SaveLog('WebServices Error:'+e.Message);
end;

procedure TjfglWebModule.SaveLog(const sMsg: string);
var
  fn:string;
  sList:TStrings;
  sNow:string;
begin
  sNow := FormatDateTime('yyyymmddhhnnss',Now);
  fn := ExtractFilePath(ParamStr(0))+'WebSrvLog.Txt';
  sList := TStringList.Create;
  try
    if fileExists(fn) then
       sList.LoadFromFile(fn);
    if sList.Count>1000 then
    begin
      sList.SaveToFile(ExtractFilePath(ParamStr(0))+sNow+'WebSrvLog.Txt');
      sList.Free;
    end;
    sList.Add(sNow+' '+sMsg);
    sList.SaveToFile(fn);
  finally
    FreeAndNil(sList);
  end;
end;

procedure TjfglWebModule.WebModule1DefaultHandlerAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
  WSDLHTMLPublish1.ServiceInfo(Sender, Request, Response, Handled);
end;

procedure TjfglWebModule.WebModuleException(Sender: TObject; E: Exception;
  var Handled: Boolean);
begin
  SaveLog('WebServices Error:'+e.Message);
end;

end.
